#ifndef ALGORITHMS
#define ALGORITHMS

#include "Types.h"

// Algorithm 0
/*
 * Event Occured
 * =========================
 * Calculate if an event occured or not according to its probabilty. 
 * Arguments: ProbabilityOfEventToOccur - a double represning the probability
 * Return Value: Returns 1 if even Occured or 0 if not
 */
BOOL EventOccured(double ProbabilityOfEventToOccur);

// Algorithm 1
/*
 * Evaluate Velocity
 * =========================
 * This functions calculates a new velocity according to the current velocity
 * and its standerd deviation
 * Arguments: Current Velocity- A vector of the current velocity	
 * 			  VelocityStdDiv - a Double reprensing the standard deviation of the velocity
 * Return Value: A vector of the new Velocity
 */
TVelocity EvaluateVelocity(TVelocity CurrentVelocity, double VelocityStdDiv);


// Algorithm 2
/*
 * Evaluate Position
 * =========================
 * This functions calculates the new position according to the
 * velocity, currnet position and its  position standerd deviation
 * Arguments: last position- A vector of the last position
 *			  New Velocity- A vector of the velocity		
 * 			  PositionStdDiv - a Double reprensing the standard deviation of the position
 * Return Value: A vector of the new position
 */
TPosition EvaluatePosition(TPosition LastPosition, TVelocity NewVelovity, double PositionStdDiv);

// Algorithm 3

// Algorithm 4
/*
 * Verify Interception
 * =========================
 * This function calculates if an interceptor should try to intercepts
 * and if the interception was successful.
 * Arguments: Rocket position- A vector of the Rocekt's position
 * 			  Interceptor position - A vector of the Interceptor's position 
 *			  MaxDistanceForInterception- A double representing the maximum distance for interception  
 *			  Succedd Probability- A double representing the success probabilty 
 *			  *InterceptDestroyedOutputPtr - This argument is an output pointer to a boolian represnting if the Interceptor exploded 
 *			  *RocketDestroyedOutputPtr -This argument is an output	pointer to a boolian represnting if the Rocket exploded  
 * Return Value: None
 */
void VerifyInterception(
	TPosition RocketPosition, 
	TPosition InterceptorPosition, 
	double MaxDistanceForInterception, 
	double SuccessProbability, 
	BOOL *InterceptDestroyedOutputPtr, BOOL *RocketDestroyedOutputPtr);

// Algorithm 5
/*
 * Determine Interceptor Direction
 * ===============================
 * This function calculates a new velocity vector for the interceptor accordint to the 
 * Rocket's position and velocity and the interseptor's position and speed.
 * Arguments: RocketPosition-  A vector of the Rocket's position
 * 			  RocketVelocity- A vector of the Rocket's velocity
 *			  Interceptor Position- A vector of the Interceptor's position 
 *			  Interceptor Speed- A double representing the size of the interceptor's velocity 
 * Return Value: A new velocity vector for the interceptor.
 */
TVelocity DetermineInterceptorDirection(
	TPosition RocketPosition, 
	TVelocity RocketVelocity, 
	TPosition InterceptorPosition,
	double InterceptorSpeed
	);

// Algorithm 6
/*
 * Add Errors To Rockets Map
 * =========================
 * this function adds an error to each rocket location. 
 * Arguments: *RocketsMap - A pointer to an array of rockets.
 * 			  NumOfRockets- An integer representing the number of flying rockets.
 * 			  RadarPosition- A vector of the Radar's position
 *			  RadarAccuracy- A double representing the manager's radar accuracy
 */
void AddErrorsToRocketsMap(TRocket *RocketsMap, int NumOfRockets, TPosition RadarPosition, double RadarAccuracy);


// Algorithm 7
/*
 * Decide If Launch Rocket
 * =========================
 * This function decides if to launch a new Rocket an initializes 
 * the parameters of the rocket if launched
 * Arguments: *InitialRocketInfoOutPtr- an output pointer arguments containig the initial info of the rocket as calculated by probability formulas     
 * 			  LaunchProbability- A double representing the launch probabilty 
 * 			  MinT- a double representing the minimum life time of the rocket
 * 			  MaxT- a double representing the maximum life time of the rocket
 * 			  MinX- a double representing the minimum X position of the launch
 * 			  MaxX- a double representing the maximum X position of the launch
 * 			  MinY- a double representing the minimum Y position of the launch
 * 			  MaxY- a double representing the maximum Y position of the launch
 * 			  MinTheta- a double representing the minimum direction angle of the launch
 * 			  MaxTheta- a double representing the maximum direction angle of the launch
 * 			  MinV- a double representing the minimum Velocity size of the rocket
 * 			  MaxV- a double representing the maximum Velocity size of the rocket
 * Return Value: A boolien represning if a rocket was launched or not.
 */
BOOL DecideIfLaunchRocket(
	TInitialRocketInfo *InitialRocketInfoOutPtr,
	double LaunchProbability, 
	int MinT, int MaxT, 
	double MinX, double MaxX, 
	double MinY, double MaxY, 
	double MinTheta, double MaxTheta, 
	double MinV, double MaxV
	);

#endif

